package cn.aloxc.tianya.reader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class Activity_test_list_simple extends Activity{
	OnItemClickListener listener = null;
	ArrayList<Map<String, String>> list = null;
	Button call = null;
	OnClickListener callListener = null;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setData();
		//setContentView(R.layout.activity_test_list_simpler);
        Bundle data = this.getIntent().getExtras();
        setTitle(data.getString("testItem"));
        
        ListView lv = new ListView(this);
        SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.activity_test_list_simpler,
        		new String[]{"姓名","性别","电话","img"},
        		new int[]{R.id.test_list_simple_name,R.id.test_list_simple_sex,R.id.test_list_simple_mobile,R.id.test_list_simple_png}
        		);
        lv.setAdapter(adapter);
        setContentView(lv);
        listener = new OnItemClickListener(){
			@SuppressWarnings("unchecked")
			public void onItemClick(AdapterView<?> parent, View v, int pos,long id) {
				//setTitle(parent.getItemAtPosition(pos).toString());
				Map<String, String> item = (Map<String, String>)parent.getItemAtPosition(pos);
				setTitle(item.get("姓名"));
			}};
		lv.setOnItemClickListener(listener);
		callListener = new Button.OnClickListener(){
			public void onClick(View btn) {
			}};
		
	}
	private void setData() {
		list = new ArrayList<Map<String, String>>();
		Map<String, String> item;
		for (int i = 0; i <= 50; i++) {
			item = new HashMap<String, String>();
			item.put("姓名", String.valueOf(i).length()==1?"张三0"+i:"张三"+i);
			item.put("性别", i%2==0?"男":"女");
			item.put("电话", String.valueOf(i).length()==1?"1303491000"+i:"130349100"+i);
			item.put("img", String.valueOf(R.drawable.phone));
			list.add(item);
			
		}
	}
}
